icon

nazo6.dev

一覧に戻る
2023/7/1 1 min read

Github Actionsでリポジトリのコミット日時が最近の時のみ処理を実行する

目次


Github Actionsでリポジトリのコミット日時が最近の時のみ処理を実行する


マイナーな内容すぎる

具体的にはこのブログを定期的にアップデートするのに使いたい

#ワークフローファイル

actions/github-scriptがめっちゃ便利だった。他でも使っていきたい。

name: Update
 
on: 
  workflow_dispatch:
  schedule:
    - cron: '0 */12 * * *'
 
jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 60
 
    steps:
    - uses: actions/github-script@v6
      with:
        result-encoding: string
        retries: 3
        script: |
          const repo = (await github.rest.repos.get({
            owner: context.repo.owner,
            repo: context.repo.repo,
          }));
          if(Date.now() - Date.parse(repo.data.pushed_at) < 12 * 60 * 60 * 1000) {
            console.log("Recent commit found, triggering deploy")
            const res = await fetch(process.env.DEPLOY_HOOK_URL, {method:"post"});
            const json = await res.json();
            if (res.status !== 200) {
              throw new Error(json.errors);
            }
          } else {
            console.log("No recent commit found, skipping deploy")
          }
      env:
        DEPLOY_HOOK_URL: ${{ secrets.DEPLOY_HOOK_URL }}
Share this article:
一覧に戻る

© 2025 nazo6. All rights reserved.